package com.tianbing.adlottery.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class UtilDataGroup {
	/**
	 * grouping data into List of list
	 * 
	 * @param dataList
	 * @param firstGroupItems
	 * @param groupSize
	 * @return
	 */
	public static List makeGroups(List dataList, int firstGroupItems, int groupSize) {
		ArrayList result = new ArrayList(0);
		if (dataList != null) {
			Iterator it = dataList.iterator();
			// skip the items before startIdx
			ArrayList firstgroup = new ArrayList(0);
			for (int i = 0; i < firstGroupItems && it.hasNext(); i++) {
				firstgroup.add(it.next());
			}
			if (firstgroup.size() > 0) {
				result.add(firstgroup);
			}

			while (it.hasNext()) {
				ArrayList onegroup = new ArrayList(0);
				for (int i = 0; it.hasNext() && i < groupSize; i++) {
					onegroup.add(it.next());
				}
				result.add(onegroup);
			}
		}
		return result;
	}
}
